package com.example.module_service.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_common.utils.RouterPath
import com.example.module_service.databinding.ItemServiceBinding
import com.example.module_service.model.ServiceEntity

class ServiceAdapter : RecyclerView.Adapter<ServiceAdapter.ServiceViewHolder>() {
    private val list = mutableListOf<ServiceEntity>()

    fun setData(data: List<ServiceEntity>) {
        list.clear()
        list.addAll(data)
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ServiceViewHolder {
        val binding = ItemServiceBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ServiceViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: ServiceViewHolder, position: Int) {
        val binding =
            DataBindingUtil.getBinding<ItemServiceBinding>(holder.itemView) ?: return
        binding.serviceIcon.setImageResource(list[position].iconRes)
        binding.serviceName.text = list[position].name

        binding.root.setOnClickListener {
            when (list[position].name) {
                "车辆管理" -> {
                    ARouter.getInstance().build(RouterPath.CAR_ACTIVITY_UI).navigation()
                }

                "车位管理" -> {
                    ARouter.getInstance().build("/module_parking/ParkingActivity").navigation()
                }

                "维修管理" -> {
                    ARouter.getInstance().build("/repair/RepairActivity").navigation()
                }
                "月卡会员"-> {
                    ARouter.getInstance().build("/module_vistor/VisitorActivity").navigation()
                }
                "访客管理"-> {
                    ARouter.getInstance().build("/vip/VipActivity").navigation()
                }
                "公告管理" -> {
                    ARouter.getInstance().build(RouterPath.NOTICE_UI).navigation()
                }
                "巡检管理"-> {
                    ARouter.getInstance().build("/patrol/PatrolActivity").navigation()
                }
                "房源信息"-> {
                    ARouter.getInstance().build("/house/HouseActivity").navigation()
                }
                "设备管理" -> {
                    ARouter.getInstance().build(RouterPath.DEVICE_UI).navigation()
                }
            }
        }
    }
    class ServiceViewHolder(val binding: ItemServiceBinding) : RecyclerView.ViewHolder(binding.root)

}